import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class DialogDemo extends StatefulWidget {
  DialogDemo({Key key}) : super(key: key);

  @override
  _DialogDemoState createState() => _DialogDemoState();
}

class _DialogDemoState extends State<DialogDemo> {

  _alertDialog() async{
    var result = await showDialog(
      context: context,
      builder: (context){
        return AlertDialog(
          title: Text('提示信息'),
          content: Text('您确定要删除吗?'),
          actions: <Widget>[
            FlatButton(
              onPressed: (){
                print('取消');
                Navigator.pop(context, 'Cancle');
              }, 
              child: Text('取消')
            ),
            RaisedButton(
              child: Text('确定'),
              onPressed: (){
                print('确定');
                Navigator.pop(context, 'Confirm');
              }
            )
          
          ],
        );
      }
    );
    print(result);
  }

  _simpleDialog() async{
    var result =  await showDialog(
      context: context,
      builder: (context){
        return SimpleDialog(
          title: Text('选择内容'),
          children: <Widget>[
            SimpleDialogOption(
              child: Text('Option A'), 
              onPressed: (){
                print('Option A');
                Navigator.pop(context, 'A');
              },
            ),
            Divider(),
            SimpleDialogOption(
              child: Text('Option B'), 
              onPressed: (){
                print('Option B');
                Navigator.pop(context, 'B');
              },
            ),
            Divider(),
            SimpleDialogOption(
              child: Text('Option C'), 
              onPressed: (){
                print('Option C');
                Navigator.pop(context, 'C');
              },
            ),
            Divider(),
            SimpleDialogOption(
              child: Text('Option D'), 
              onPressed: (){
                print('Option D');
                Navigator.pop(context, 'D');
              },
            )
          ],
        );
      }
    );
    print(result);
  }

  _modalBottomSheet() async{
    var result = await showModalBottomSheet(
      context: context, 
      builder: (context){
        return Container(
          height: 200,
          child: Column(
            children: <Widget>[
              ListTile(
                title: Text('分析A'),
                onTap: (){
                  Navigator.pop(context, '分析A');
                },
              ),
              Divider(),
              ListTile(
                title: Text('分析B'),
                onTap: (){
                  Navigator.pop(context, '分析B');
                },
              ),
              Divider(),
              ListTile(
                title: Text('分析C'),
                onTap: (){
                  Navigator.pop(context, '分析C');
                },
              )
            ], 
          ),

        );
      }
    );
    print(result);
  }

  _toast(){
    Fluttertoast.showToast(
      msg: "提示信息",
      toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.TOP,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.black,
      textColor: Colors.white,
      fontSize: 16.0
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Dialog'), 
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              child: Text('alert弹出框-AlertDialog'),
              onPressed: _alertDialog
            ),
            SizedBox(height: 20),
            RaisedButton(
              child: Text('select弹出框-SimpleDialog'),
              onPressed: _simpleDialog
            ),
            SizedBox(height: 20),
            RaisedButton(
              child: Text('ActionSheet底部弹出框-showModalBottomSheet'),
              onPressed: _modalBottomSheet
            ),
            SizedBox(height: 20),
            RaisedButton(
              child: Text('toast-flutter toast第三方库'),
              onPressed: _toast
            )
          ],
        ), 
      ),
    );
  }
}